import type { AddCartParams, CartItem, PutMemberCartParams } from '@/types/cart'
import { myGet, myPost, myRequest } from '@/utils/request'

/** 添加购物车 */
export const addCartAPI = (data: AddCartParams) => {
  return myPost('/member/cart', data)
}

/** 获取购物车列表 */
export const getCartListAPI = () => {
  return myGet<CartItem[]>('/member/cart')
}

/** 删除购物车 */
export const deleteCartAPI = (ids: string[]) => {
  return myRequest({
    method: 'DELETE',
    url: '/member/cart',
    data: {
      ids
    }
  })
}

/** 修改购物车单品 */
export const putMemberCartAPI = (skuId: string, data: PutMemberCartParams) => {
  return myRequest({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
    custom: {
      loading: false // 不显示 loading
    }
  })
}

/** 修改购物车全选状态 */
export const putMemberCartSelectedAllAPI = (data: { selected: boolean }) => {
  return myRequest({
    method: 'PUT',
    url: '/member/cart/selected',
    data,
    custom: {
      loading: false // 不显示 loading
    }
  })
}
